package com.ct.controller.shipping;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ct.application.commons.vo.StatusRequest;
import com.ct.application.shipping.model.po.ChuanYuanKuDongTaiSavePO;
import com.ct.application.shipping.model.po.ChuanYuanKuDongTaiSearchPO;
import com.ct.application.shipping.model.vo.ChuanYuanKuDongTaiVO;
import com.ct.application.shipping.service.ChuanYuanKuDongTaiService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import com.ct.shipping.model.ChuanYuanKuDongTaiMapperSearchPO;
import com.ct.shipping.model.ChuanYuanKuDongTaiMapperVO;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 船员动态配置
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
@PermissionApi(title = "船员动态",path="/api/v1/chuanyuandongtai",code = "U1000",sorted = 10)
public class ChuanYuanKuDongTaiController extends BaseController {

    @Resource
    private ChuanYuanKuDongTaiService chuanYuanKuDongTaiService;

    /**
     * 查询单独船员动态模块列表数据
     */
    @PostMapping("/dongtai/list")
    @PermissionApi(title = "查询单独船员动态模块列表数据",path="/api/v1/dongtai/list",code = "U1007",sorted = 7)
    public IPage<ChuanYuanKuDongTaiMapperVO> findDongTaiTais(@Validated @RequestBody ChuanYuanKuDongTaiMapperSearchPO searchPO) {
        return chuanYuanKuDongTaiService.findDongTai(searchPO);
    }



    /**
     * 查询船员动态列表
     * @param chuanYuanKuDongTaiSearchPO
     * @return
     */
    @PostMapping("/chuanyuandongtai/list")
    @PermissionApi(title = "查询船员动态列表",path="/api/v1/chuanyuandongtai/list",code = "U1001",sorted = 1)
    public Page<ChuanYuanKuDongTaiVO> findChuanYuanKuDongTais(@Validated @RequestBody ChuanYuanKuDongTaiSearchPO chuanYuanKuDongTaiSearchPO) {
        return chuanYuanKuDongTaiService.findChuanYuanKuDongTai(chuanYuanKuDongTaiSearchPO);
    }

    /**
     * 保存和更新
     *
     * @param savePO
     * @return
     */
    @PostMapping("/chuanyuandongtai/saveupdate")
    @ApiLog("船员动态保存和更新")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员动态保存和更新",path="/api/v1/chuanyuandongtai/saveupdate",code = "U1003",sorted = 3)
    public Boolean saveUpdateChuanYuanKuDongTai(@Validated @RequestBody ChuanYuanKuDongTaiSavePO savePO) {
        if (Objects.nonNull(savePO.getId())){
            return chuanYuanKuDongTaiService.updateChuanYuanKuDongTai(savePO);
        }else {
            return chuanYuanKuDongTaiService.saveChuanYuanKuDongTai(savePO);
        }
    }

    /**
     * 根据id查询船员动态
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuandongtai/get/{id}")
    @PermissionApi(title = "根据id查询船员动态",path="/api/v1/chuanyuandongtai/get/{id}",code = "U1004",sorted = 4)
    public ChuanYuanKuDongTaiVO getChuanYuanKuDongTaiById(@PathVariable("id") Long id) {
        return chuanYuanKuDongTaiService.getChuanYuanKuDongTai(id);
    }


    /**
     * 根据id删除船员动态
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuandongtai/del/{id}")
    @ApiLog("根据id删除船员动态")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "根据id删除船员动态",path="/api/v1/chuanyuandongtai/del/{id}",code = "U1005",sorted = 5)
    public Boolean delChuanYuanKuDongTaiById(@PathVariable("id") Long id) {
        return chuanYuanKuDongTaiService.delChuanYuanKuDongTai(id);
    }

    /**
     * 修改状态
     *
     * @return
     */
    @PostMapping("/chuanyuandongtai/update/status")
    @ApiLog("船员动态修改状态")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员动态修改状态",path="/api/v1/chuanyuandongtai/update/status",code = "U1006",sorted = 6)
    public Boolean updateStatus(@Validated @RequestBody StatusRequest statusRequest) {
        return chuanYuanKuDongTaiService.updateStatus(statusRequest);
    }
}
